import gtk

class ScaleDialog(gtk.Dialog):
    def __init__(self, header, min, max, initial):
        # Construct superclass.
        gtk.Dialog.__init__(self, header)
        
        # Add widgets.
        self.add_button(gtk.STOCK_CANCEL, 0)
        self.add_button(gtk.STOCK_OK, 1)
        self.scale = gtk.HScale()
        self.scale.set_digits(0)
        self.scale.set_range(min, max)
        self.scale.set_increments(1, 10)
        self.scale.set_value(initial)
        self.scale.set_sensitive(True)
        self.vbox.pack_start(self.scale)
        
    def do_it(self):
        self.show_all()
        rc = self.run()
        self.hide_all()
        if rc == 1:
            # Ok button was clicked. Return the value given by the scale.
            return self.scale.get_value()
        else:
            # Cancel was clicked. Return an error indicator.
            return -1.0
